package com.admin.education.services.Implements;

import com.admin.education.dataTransferObject.ServicesExcuteResult;
import com.admin.education.dataTransferObject.role.RoleTransfer;
import com.admin.education.dataTransferObject.role.mapper.RoleMapper;
import com.admin.education.models.QRole;
import com.admin.education.models.Role;
import com.admin.education.repositories.RoleRepository;
import com.admin.education.services.Interfaces.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import java.util.List;
@Service
@Validated
public class RoleService implements IRoleService {
    @Autowired
    private RoleMapper roleMapper;
    private QRole qRole;
    @Autowired
    private RoleRepository roleRepository;
    public RoleService(){
        qRole = QRole.role;
    }

    @Override
    public ServicesExcuteResult<List<RoleTransfer>> queryRoles() {
        ServicesExcuteResult<List<RoleTransfer>> servicesExcuteResult = new ServicesExcuteResult<>();

        List<Role>  roles= this.roleRepository.selectFrom(qRole).where(qRole.isValid.eq(true),qRole.adminManage.eq(false)).fetch();

        servicesExcuteResult.setData(roleMapper.mapFrom(roles));
        servicesExcuteResult.setSuccess(true);

        return servicesExcuteResult;
    }
}
